/* eslint-disable */
export class CommandCompletionMeta {
  constructor(name, doc, command, args) {
    this.name = name;
    this.doc = doc;
    this.command = { id: command, title: name, tooltip: doc, arguments: args };
  }

  getDetail() {
    return this.doc;
  }

  getLabel() {
    return this.name;
  }

  toCompletionItem(currentWord, position) {
    const item = CommonCompletionItem.instance(
      this.name,
      '',
      window.manaco.languages.CompletionItemKind.Event,
      currentWord,
      position,
    );
    item.detail = this.doc;
    item.documentation = this.doc;
    item.command = this.command;
    return item;
  }

  name;
  doc;
  command;
}

export class ConstantCompletionMeta {
  constructor(name, use, doc) {
    this.name = name;
    this.use = use;
    this.doc = doc;
  }
  toCompletionItem(currentWord, position) {
    const item = CommonCompletionItem.instance(
      this.name,
      this.use,
      window.monaco.languages.CompletionItemKind.Constant,
      currentWord,
      position,
    );
    item.detail = this.doc;
    item.documentation = this.doc;
    return item;
  }

  getLabel() {
    return this.name;
  }

  getDetail() {
    return this.doc;
  }
}

export class CommonCompletionItem {
  constructor(label, insertText, currentWord, position) {
    this.insertText = insertText;
    this.kind = window.monaco.languages.CompletionItemKind.Variable;
    this.label = label;
    this.range = {
      startLineNumber: position.lineNumber,
      startColumn: currentWord.startColumn,
      endLineNumber: position.lineNumber,
      endColumn: currentWord.endColumn, // position.column + insertText.length
    };
  }

  static var(label, insertText, currentWord, position) {
    return new CommonCompletionItem(label, insertText, currentWord, position);
  }

  static instance(label, insertText, kind, currentWord, position) {
    const res = new CommonCompletionItem(label, insertText, currentWord, position);
    res.kind = kind;
    return res;
  }
}
